package casa.depesos.app.com.frag;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import casa.depesos.app.com.activity.MainActivity;
import casa.depesos.app.com.databinding.FragmentTakeFailBinding;
import casa.depesos.app.com.http.ReqCallback;
import casa.depesos.app.com.http.bean.TakeFailBean;
import casa.depesos.app.com.http.data.TakeFail;
import casa.depesos.app.com.http.req.FailReq;
import casa.depesos.app.com.it.Refreshable;
import casa.depesos.app.com.utils.Report;
import casa.depesos.app.com.utils.Utils;

public class TakeFailFragment extends BannerBaseFragment implements Refreshable {

    FragmentTakeFailBinding binding;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        Report.show("ACTION_SS_004");
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragmentTakeFailBinding.inflate(inflater, container, false);
        binding.rela.setPadding(0, Utils.getStatusBarHeight(getActivity()), 0, 0);

        binding.frame.tv.setText("Cuenta atrás de solicitud de retiro");
        binding.frame.frame.setOrientation(LinearLayout.VERTICAL);
        ((ViewGroup.MarginLayoutParams) binding.frame.time.getLayoutParams()).topMargin = Utils.dp2Px(getActivity(), 10);

        getName(binding.top);
        getUnRead(binding.top);
        showMsg(binding.msg, binding.scroll);
        getBanner(binding.banner);

        getData();

        return binding.getRoot();
    }

    private void getData() {
        showLoading();
        new FailReq().req(new ReqCallback<TakeFailBean>() {
            @Override
            public void callback(boolean success, TakeFailBean bean) {
                hideLoading();
                if (success) {
                    show(bean.info);
                }
            }
        });
    }

    @Override
    protected void countDownTimeout() {
        ((MainActivity) getActivity()).showHome(1);
    }

    private void show(TakeFail info) {
        startCountDown(binding.frame, info.getCountDownTime());
    }

    @Override
    public void refresh() {
        getData();
    }
}
